home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
CUGUK
/
PC_LIBS
/
C045.ZIP
/
BTREE.ARC
/
BTREE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-05
|
2KB
|
90 lines
#include <stdio.h>
#include <dos.h>
#include "cstruct.h"
#include "datatype.h"
#include "access.h"
#include "btutil.h"
#include "btreeinc.h"
#define MAIN
#include "globals.h"
main(int argc, char * argv[])
{
tapage * getapage(indexfile *, int);
char ch;
int seed;
char datfile[32], nnxfile[32], cnxfile[32];
if (argc < 2) {
printf("Syntax: btree filename [seed]\n");
exit (0);
}
strcpy(datfile, argv[1]);
strcat(datfile, ".dat");
strcpy(cnxfile, argv[1]);
strcat(cnxfile, ".ixc");
strcpy(nnxfile, argv[1]);
strcat(nnxfile, ".ixn");
seed = (argc > 2) ? atoi(argv[2]) : 1;
srand(seed);
clearwindow(1,1, 80,25);
initindex();
initkeyboard();
if ( (datfp = openfile (datfile)) == NULL ) {
ch = select("Data files missing. Create new files (y/n)", "YyNn");
if (toupper(ch) == 'Y') {
datfp = makefile( datfile, MAXDATARECSIZE);
cnxfp = makeindex(cnxfile, 15, 0);
nnxfp = makeindex(nnxfile, 25, 1);
}
else {
clearwindow(1,1, 80,25);
exit (0);
}
}
else if ( (cnxfp = openindex(cnxfile)) == NULL ||
(nnxfp = openindex(nnxfile)) == NULL ) {
ch = select("Index files missing. Reconstruct indice? (y/n) ", "YyNn");
if (toupper(ch) == 'Y') {
cnxfp = makeindex(cnxfile, 15, 0);
nnxfp = makeindex(nnxfile, 25, 1);
reconstruct();
select("Index files reconstruction completed. <Return> to continue", "\x0d");
}
else {
clearwindow(1,1, 80,25);
exit (0);
}
}
do {
update_record_count();
clearwindow(1,4, 80,21);
ch = select("Select : U)pdate, C)reate, D)elete, L)ist, Q)uit",
"ucdlqUCDLQ");
if ((ch = toupper(ch)) == 'L')
list();
else if (ch == 'D')
delete();
else if (ch == 'C')
create();
else if (ch == 'U')
update();
} while (ch != 'Q');
closeindex(nnxfp);
closeindex(cnxfp);
closefile(datfp);
clearwindow(1,1, 80,25);
}